package com.ybliu.canal.handler;

import com.alibaba.fastjson2.JSON;
import com.ybliu.canal.domain.EmployeeMedicineDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

/**
 * Created by linlinyeyu on 2023/12/17
 */
@Service
@CanalTable("hire_medicine")
public class MedicineHandler implements EntryHandler<EmployeeMedicineDo> {
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @Override
    public void insert(EmployeeMedicineDo employeeMedicineDo) {
        redisTemplate.opsForValue().set("employee_medicine:" + employeeMedicineDo.getId(), JSON.toJSONString(employeeMedicineDo));
    }

    @Override
    public void update(EmployeeMedicineDo before, EmployeeMedicineDo after) {
        redisTemplate.opsForValue().set("employee_medicine:" + after.getId(), JSON.toJSONString(after));
    }

    @Override
    public void delete(EmployeeMedicineDo employeeMedicineDo) {
        redisTemplate.delete("employee_medicine:" + employeeMedicineDo.getId());
    }
}
